import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
import 'minimalist_mode_intro_screen.dart';
import 'parenting_mode_dialog.dart';
import 'pregnancy_preparation_mode_dialog.dart';
import 'pregnancy_mode_dialog.dart';

class SettingsScreen extends StatefulWidget {
  const SettingsScreen({super.key});

  @override
  State<SettingsScreen> createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppTheme.background,
      appBar: AppBar(
        backgroundColor: AppTheme.white,
        elevation: 0,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
          color: AppTheme.textPrimary,
        ),
        title: const Text(
          '设置',
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
            color: AppTheme.textPrimary,
          ),
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            
            _buildSettingsGroup([
              _buildSettingItem('育儿模式', true, onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => const ParentingModePage()),
                );
              }),
              _buildSettingItem('备孕模式', true, onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => const PregnancyPreparationModePage()),
                );
              }),
              _buildSettingItem('怀孕模式', true, onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => const PregnancyModePage()),
                );
              }),
              _buildSettingItem('青少年模式', true),
              _buildSettingItem('亲友模式', true),
              _buildSettingItem('极简模式', true, onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => const MinimalistModeIntroScreen()),
                );
              }),
              _buildSettingItem('消息通知', true),
              _buildSettingItem('智能设备', true),
              _buildSettingItem('个人信息与权限', true),
              _buildSettingItem('通用', true),
            ]),
            
            _buildSettingsGroup([
              _buildSettingItem('社区内容偏好调节', true),
              _buildSettingItem('社区公约', true),
            ]),
            
            _buildSettingsGroup([
              _buildSettingItem('关于月伴', true, isNew: true),
              _buildSettingItem('分享月伴', true),
            ]),
            
            
            Container(
              padding: const EdgeInsets.only(top: 30, bottom: 50),
              child: const Column(
                children: [
                  Text(
                    '《个人信息收集清单》《第三方信息共享清单》',
                    style: AppTheme.smallStyle,
                  ),
                  SizedBox(height: 8),
                  Text(
                    '《隐私政策》',
                    style: AppTheme.smallStyle,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildSettingsGroup(List<Widget> children) {
    return Container(
      margin: const EdgeInsets.only(top: 8),
      color: AppTheme.white,
      child: Column(
        children: children,
      ),
    );
  }

  Widget _buildSettingItem(String title, bool showArrow, {bool isVip = false, bool isNew = false, void Function()? onTap}) {
      return GestureDetector(
        onTap: onTap,
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
          child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Text(title, style: AppTheme.bodyStyle),
                if (isVip) const SizedBox(width: 6),
                if (isVip)
                    Container(
                      padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
                      decoration: const BoxDecoration(
                        color: Colors.purple,
                        borderRadius: BorderRadius.all(Radius.circular(2)),
                      ),
                    child: const Text(
                      'VIP',
                      style: TextStyle(
                        fontSize: 10,
                        color: AppTheme.white,
                      ),
                    ),
                  ),
                if (isNew) const SizedBox(width: 6),
                if (isNew)
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1),
                    decoration: const BoxDecoration(
                      color: AppTheme.primaryColor,
                      borderRadius: BorderRadius.all(Radius.circular(2)),
                    ),
                    child: const Text(
                      'new',
                      style: TextStyle(
                        fontSize: 10,
                        color: AppTheme.white,
                      ),
                    ),
                  ),
              ],
            ),
            if (showArrow) const Icon(Icons.chevron_right, color: AppTheme.textLight)
          ],
        ),
      ),
    );
  }
}
